﻿/*----------------------------------------------------------------
//  <copyright file="UserOutputDto.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2023-12-12 11:41</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.Identity.Dtos
{
    #region "输出DTO：用户信息"
    /// <summary>
    /// 输出DTO：用户信息
    /// </summary>
    [MapFrom(typeof(User))]
    public class UserOutputDto : IOutputDto, IDataAuthEnabled
    {
        #region "属性"
        #region "获取或设置 用户编号"
        /// <summary>
        /// 获取或设置 用户编号
        /// </summary>
        public long Id { get; set; }
        #endregion
        #region "获取或设置 用户名"
        /// <summary>
        /// 获取或设置 用户名
        /// </summary>
        public string UserName { get; set; }
        #endregion
        #region "获取或设置 用户昵称"
        /// <summary>
        /// 获取或设置 用户昵称
        /// </summary>
        public string NickName { get; set; }
        #endregion
        #region "获取或设置 电子邮箱"
        /// <summary>
        /// 获取或设置 电子邮箱
        /// </summary>
        public string Email { get; set; }
        #endregion
        #region "获取或设置 邮箱是否已确认"
        /// <summary>
        /// 获取或设置 邮箱是否已确认
        /// </summary>
        public bool EmailConfirmed { get; set; }
        #endregion
        #region "获取或设置 手机号码"
        /// <summary>
        /// 获取或设置 手机号码
        /// </summary>
        public string PhoneNumber { get; set; }
        #endregion
        #region "获取或设置 手机是否已确认"
        /// <summary>
        /// 获取或设置 手机是否已确认
        /// </summary>
        public bool PhoneConfirmed { get; set; }
        #endregion

        #region "获取或设置 性别"
        /// <summary>
        /// 获取或设置 性别
        /// </summary>
        public Gender Gender { get; set; }
        #endregion
        #region "获取或设置 生日"
        /// <summary>
        /// 获取或设置 生日
        /// </summary>
        public DateTime? Birthday { get; set; }
        #endregion
        #region "获取或设置 血型"
        /// <summary>
        /// 获取或设置 血型
        /// </summary>
        public string BloodType { get; set; }
        #endregion
        #region "获取或设置 标签"
        /// <summary>
        /// 获取或设置 标签
        /// </summary>
        public ICollection<string> Tag { get; set; }
        #endregion
        #region "获取或设置 头衔"
        /// <summary>
        /// 获取或设置 头衔
        /// </summary>
        public ICollection<string> Title { get; set; }
        #endregion
        #region "获取或设置 地址"
        /// <summary>
        /// 获取或设置 地址
        /// </summary>
        public string Address { get; set; }
        #endregion
        #region "获取或设置 简介"
        /// <summary>
        /// 获取或设置 简介
        /// </summary>
        public string Profile { get; set; }
        #endregion
        #region "获取或设置 个性签名"
        /// <summary>
        /// 获取或设置 个性签名
        /// </summary>
        public string Sign { get; set; }
        #endregion
        #region "获取或设置 备注"
        /// <summary>
        /// 获取或设置 备注
        /// </summary>
        public string Remark { get; set; }
        #endregion

        #region "获取或设置 主页"
        /// <summary>
        /// 获取或设置 主页
        /// </summary>
        [DisplayName("主页")]
        public string HomePath { get; set; }
        #endregion

        #region "获取或设置 农历生日"
        /// <summary>
        /// 获取或设置 农历生日
        /// </summary>
        public DateTime? ChineseBirthday { get; set; }
        #endregion
        #region "获取或设置 年龄"
        /// <summary>
        /// 获取或设置 年龄
        /// </summary>
        public int Age { get; set; }
        #endregion
        #region "获取或设置 生肖"
        /// <summary>
        /// 获取或设置 生肖
        /// </summary>
        public ChineseZodiacSign? ZodiacSign { get; set; }
        #endregion
        #region "获取或设置 星座"
        /// <summary>
        /// 获取或设置 星座
        /// </summary>
        public StarSign? StarSign { get; set; }
        #endregion

        #region "获取或设置 当任何用户锁定结束时，UTC的日期和时间"
        /// <summary>
        /// 获取或设置 当任何用户锁定结束时，UTC的日期和时间
        /// </summary>
        public DateTimeOffset? LockoutEnd { get; set; }
        #endregion
        #region "获取或设置 指示用户是否可以被锁定的标志"
        /// <summary>
        /// 获取或设置 指示用户是否可以被锁定的标志
        /// </summary>
        public bool LockoutEnabled { get; set; }
        #endregion
        #region "获取或设置 当前用户失败的登录尝试次数"
        /// <summary>
        /// 获取或设置 当前用户失败的登录尝试次数
        /// </summary>
        public int AccessFailedCount { get; set; }
        #endregion
        #region "获取或设置 是否锁定当前信息"
        /// <summary>
        /// 获取或设置 是否锁定当前信息
        /// </summary>
        public bool IsLocked { get; set; }
        #endregion

        #region "获取或设置 创建时间 ICreatedTime、ICreationAudited  可装载接口，在数据创建时可自动设置当前时间"
        /// <summary>
        /// 获取或设置 创建时间
        /// </summary>
        [DisplayName("创建时间")]
        public DateTime CreatedTime { get; set; }
        #endregion

        #region "获取或设置 角色信息集合"
        /// <summary>
        /// 获取或设置 角色信息集合
        /// </summary>
        public string[] Roles { get; set; }
        #endregion

        //Implementation of IDataAuthEnabled
        #region "获取或设置 是否可更新"
        /// <summary>
        /// 获取或设置 是否可更新
        /// </summary>
        public bool Updatable { get; set; }
        #endregion
        #region "获取或设置 是否可删除"
        /// <summary>
        /// 获取或设置 是否可删除
        /// </summary>
        public bool Deletable { get; set; }
        #endregion

        #endregion

        #region "构造函数"
        #region "初始化一个用户信息输出DTO的新实例"
        /// <summary>
        /// 初始化一个用户信息输出DTO <see cref="UserOutputDto"/> 的新实例
        /// </summary>
        public UserOutputDto()
        { }
        #endregion
        #region "初始化一个用户信息输出DTO的新实例"
        /// <summary>
        /// 初始化一个用户信息输出DTO <see cref="UserOutputDto"/> 的新实例
        /// </summary>
        /// <param name="user">用户实体数据</param>
        /// <param name="detail">用户详情实体数据</param>
        public UserOutputDto(User user, UserDetail detail)
        {
            Id = user.Id;
            UserName = user.UserName;
            NickName = user.NickName;
            Email = user.Email;
            EmailConfirmed = user.EmailConfirmed;
            PhoneNumber = user.PhoneNumber;
            PhoneConfirmed = user.PhoneConfirmed;

            Gender = detail.Gender;
            Birthday = detail.Birthday;
            BloodType = detail.BloodType;
            Tag = detail.Tag.Split(",", true);
            Title = detail.Title.Split(",", true);
            Address = detail.Address;
            Profile = detail.Profile;
            Sign = detail.Sign;
            Remark = detail.Remark;
            HomePath = detail.HomePath;

            var chineseCalendar = detail.Birthday.HasValue ? detail.Birthday.Value.ToChineseCalendar() : null;
            var userAge = detail.Birthday.HasValue ? (DateTime.Now.Year - detail.Birthday.Value.Year + 1) > 0 ? (DateTime.Now.Year - detail.Birthday.Value.Year + 1) : 0 : 0;
            ChineseBirthday = chineseCalendar?.ChineseCalendarDate;
            Age = userAge;
            ZodiacSign = chineseCalendar?.ZodiacSign;
            StarSign = chineseCalendar?.StarSign;

            LockoutEnd = user.LockoutEnd;
            LockoutEnabled = user.LockoutEnabled;
            AccessFailedCount = user.AccessFailedCount;
            IsLocked = user.IsLocked;

            CreatedTime = user.CreatedTime;
        }
        #endregion

        #endregion

    }
    #endregion

}
